package com.xc.content.controller;

import com.xc.content.model.dto.CourseTeacherDto;
import com.xc.content.model.po.CourseTeacher;
import com.xc.content.service.CourseTeacherService;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author daxiaa
 */
@Slf4j
@RestController
@RequestMapping("courseTeacher")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @GetMapping("/list/{courseId}")
    List<CourseTeacher> list(@PathVariable("courseId") Long courseId) {
        log.info("根据课程ID查询教师信息:{}", courseId);
        return courseTeacherService.queryByCourseId(courseId);

    }

    @PostMapping
    void courseTeacher(@RequestBody @Validated CourseTeacherDto courseTeacherDto) {
        log.info("新增或修改教师信息:{}", courseTeacherDto);
        CourseTeacher courseTeacher = new CourseTeacher();
        BeanUtils.copyProperties(courseTeacherDto, courseTeacher);
        courseTeacherService.saveOrUpdate(courseTeacher);

    }

    @DeleteMapping("/course/{courseId}/{id}")
    void course(@PathVariable("courseId") Long courseId, @PathVariable("id") Long id) {
        log.info("删除教师:{},{}", courseId, id);
        courseTeacherService.removeById(id);

    }
}
